
//Ajaxéä¿¡ã®ã¿ã¤ã ã¢ã¦ã
var AJAX_TIMEOUT = 30000;


$(document).ready(function(){

		$(".menu").find("li").each(function(i) {
		    $(this).bind("click", function() {
			    $(".menu").find("li").each(function(i) {
			        $(this).removeClass("selected");
			    });
		        $(this).addClass("selected");
		    });
	    });
	
	//éµä¾¿çªå·æ¤ç´¢ã®åæå¤è¨­å®
	$.fn.zipsearch.defaults = {
			url: "AjaxHandler.do?ajaxBizId=zipSearch",							//æ¤ç´¢å®è¡ç¨ã®URL
			noResultMessage:"<br/>æ¤ç´¢å¯¾è±¡ã®ä½æã¯å­å¨ãã¾ããã"	//ä½æãå­å¨ããªãã£ãå ´åã«è¡¨ç¤ºããæå­å
	}
	
	//ããã¯ã¹ãã¼ã¹å¯¾å¿
	$(document).bind('keydown', 'backspace',function (evt){
		if(($(evt.target).is(':input:not(:hidden, :button, :submit, :image, :checkbox, :radio, :reset, :file)') || $(evt.target).is('textarea'))&& !$(evt.target).is('select'))
		{
			return true;
		}
		else
		{
			evt.stopPropagation( );
			evt.preventDefault( );
			return false;
		}
	});
       
	//Ajaxéä¿¡ã®å±éãªãã·ã§ã³è¨­å®
	$.ajaxSetup(
				{
				//æå­åãå¯¾ç­ã®çºãPOSTã«åºå®
		        type: "POST",
		        //IEãã­ã£ãã·ã³ã°ãã¦ãã¾ãã®ãé²ã
		        cache: false,
		        timeout: AJAX_TIMEOUT,
		        async: true,
		        //ã¨ã©ã¼å¦ç
		        // .ajaxError()ã§ã¨ã©ã¼ãæã¾ããã¨ã¿ã¤ã ã¢ã¦ãã®ã¹ãã¼ã¿ã¹ãè¦ããªãã£ã½ã
		        // XMLHttpRequestããªãã¨ãã«XMLHttpRequest.statusãåç§ãããã¨ããã¨ã¨ã©ã¼ã«ãªãããã ã
		        // ã¨è¨ãããã§setUpã®ãªãã·ã§ã³ã§ã¨ã©ã¼ãæã¾ãã¦statusãã¨ã©ã¼ã®ã¨ãã¯XMLHttpRequest.statusãè¦ã¦
		        // timeoutã®å ´åã¯åç­ç¡ç¨ã§ã¨ã©ã¼ãã¼ã¸ã«é£ã°ãæ§ã«ä¿®æ­£ã
		        error:function (XMLHttpRequest, status) {
						if( ( status == "error" && XMLHttpRequest.status != 200 && XMLHttpRequest.status != 412 && XMLHttpRequest.status != 0) ||
								status =="timeout"	)
						{							
							location.href="./Z3104W.do";
						}
					}
				}
			);
	
	//Ajaxéä¿¡æã«"éä¿¡ä¸­"ã¡ãã»ã¼ã¸ãè¡¨ç¤ºããè¨­å®
	// BlockUIãã©ã°ã¤ã³ãå©ç¨ãã¦ãå³ä¸ã«ããã£ã½ããã®ãè¡¨ç¤ºãã
	// è¡¨ç¤ºããè¦ç´ ã¯ãfooterã®HTMLã«éè¡¨ç¤ºã§ç¨æãã¦ãã
	//Tko2380 "éä¿¡ä¸­"ã¡ãã»ã¼ã¸ãè¡¨ç¤ºããªã
	/*
	$().ajaxStart(function(){
		 $.blockUI({ 
		            message: $('#blockMessage'),
		            fadeIn: 10, 
		            fadeOut: 10, 
		            //timeout: 3000, 
		            showOverlay: false, 
		            centerY: false, 
		            css: { 
		                width: '120px', 
		                height: '25px', 
		                top: '55px', 
		                left: '', 
		                right: '10px', 
		                border: 'none', 
		                padding: '5px', 
		                backgroundColor: '#dc143c', 
		                '-webkit-border-radius': '10px', 
		                '-moz-border-radius': '10px', 
		                opacity: '0.8', 
		                color: '#fff' 
		            } 
		        }); 
		        
		        
		        }	
			).ajaxStop(function(){
													$.unblockUI();
												}
		);
		*/
		
		//éµä¾¿çªå·æ¤ç´¢æ©è½ãæå¹å
		$(".zipcode").each(function(){$(this).zipsearch();});
		
			
		//å¹´ã»æã»æ¥å¥åæ¬ã®å¶å¾¡
		//ã»ã¯ãªãã¯ã»ãã©ã¼ã«ã¹åå¾æã«é¸æç¶æã¨ãã
		//ã»ã­ã¹ããã©ã¼ã«ã¹æã®åã¼ã­åã
		//ã»å¥åãã¹ã¯
		$(".warekiInput :text").focus(
						function(){
// å¹´ã»æã»æ¥å¥åæ¬ã«backspaceã®å¯¾å¿ã2009-12-15ãstart
//								$(this).select();
// å¹´ã»æã»æ¥å¥åæ¬ã«backspaceã®å¯¾å¿ã2009-12-15ãend								
						}
					).click(
						function(){
							$(this).select();
							return false;
						}
					).blur(
						function(){
							if($(this).val().replace(/[-\s]/g, "").length == 1){
								$(this).val("0" + $(this).val());
							}
						}
					).keydown(//[æéå¯¾å¿:SIG1_3069 start]
						function(){
							if(event.keyCode==13){
								if($(this).val().replace(/[-\s]/g, "").length == 1){
									$(this).val("0" + $(this).val());
								}							
							}
						});
					//[æéå¯¾å¿:SIG1_3069 end]
						
		//åç»é¢ãå¹´ã»æã»æ¥é ç®ã§ãæ°å¤ä»¥å¤ã®å¥åãã¹ã¯ãå¤ãã				
		//.mask("99",{placeholder:""});
		
						
		//æåã®å¥åé ç®ã«ãã©ã¼ã«ã¹ãå½ã¦ã
		//å¨ã¦ã®inputã¿ã°ã®ãã¡ãhiddenã§ãbuttonã§ãç¡ãè¦ç´ ãé¸æ
		//[æéå¯¾å¿:UTG0T_0013 start]
		//$(":input:not(:hidden, :button):first").focus();
		$(":input:not(:hidden, :button, :submit, :image):first").focus();
		//[æéå¯¾å¿:UTG0T_0013 end]
		
		//ãã¿ã³ã®äºåº¦æ¼ãé²æ­¢
		$("form").submit(function(){
				noMoreClick($("form"));
			});
		function Set(button) {
			setTimeout(function() { button.disabled = true; }, 1);
		}
		function unSet(button) {
			setTimeout(function() { button.disabled = false; }, 1000);
		}

  		//ã¨ã©ã¼çºçç®æããã¤ã©ã¤ããã
  		//strutsã®errorStyleClassã§æå®ä¸å¯è½ãªé ç®ï¼Beanãã­ããã£ã¨ãã¦ã¯æã£ã¦ããªããåæ¦ãç¸é¢ãã§ãã¯ç­ï¼
  		//ã¯ãã¨ã©ã¼çºçã®ãã©ã°ã¨ãã¦ã"has_error"ã¯ã©ã¹ãæã¤ç©ºã®spanã¿ã°ãåºåãã¦ãã
  		//ãããå«ãtdè¦ç´ ã®åé¨ã®txtè¦ç´ ã«ãã¨ã©ã¼ããã®å¤å®ã¯ã©ã¹"error"ãä»ä¸ãã
  		$("td:not(:has(table)):has(span.has_error)").find(":input:not(:button,:image,:hidden,:submit),select").addClass("error");
  		//ã¨ã©ã¼å¤å®ã¯ã©ã¹"error"ãæã¤è¦ç´ ãå­å¨ãã td ã¿ã°ã®ç´åã® th è¦ç´ ã«ãã¨ã©ã¼å¤å®ã¯ã©ã¹"errorãä»å ãã
  		$("td:not(:has(table)):has(.error)").prev().removeClass("item").addClass("error");
  		
		//æä»å¶å¾¡åç§ã¢ã¼ãè¨­å®
//		if($("#refmodeFlg").val() == "1"){
//				$(":input:not(:text,:checkbox,:radio)").attr("disabled", "disabled");
//				$(":text").attr("readonly","readonly").addClass("readonly");
//				$(":text,:checkbox,:radio").click(
//						function(event){
//							event.preventDefault();
//							return false;
//						}
//					 );
//		}
	}
);

//ãã¿ã³ã®äºåº¦æ¼ãé²æ­¢
function noMoreClick($target){	
	$target.find(":submit,:image,:button").each(function(){		
		if(this.disabled == false){
			Set(this);
			unSet(this);
		}
	});
}

function Set(button) {
	setTimeout(function() { button.disabled = true; }, 1);
}
function unSet(button) {
	setTimeout(function() { button.disabled = false; }, 1000);
}
